package cn.hxlc.tie.demo.modular.zr.material.controller;/*
 @author rui
 @date 2021/7/15 --12:03
*/

import cn.hxlc.tie.demo.modular.zr.material.model.params.MaterialParam;
import cn.hxlc.tie.demo.modular.zr.material.model.result.MaterialResult;
import cn.hxlc.tie.demo.modular.zr.material.service.MaterialService;
import cn.hxlc.tie.libs.scanner.annotation.GetResource;
import cn.hxlc.tie.libs.scanner.annotation.PostResource;
import cn.hxlc.tie.libs.scanner.stereotype.ApiResource;
import cn.hxlc.tie.model.page.PageResult;
import cn.hxlc.tie.model.web.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name="物料管理_主表",path="/material")
@Api(tags="物料")
public class ZrProductController {
    @Autowired
    private MaterialService materialService;

    @GetResource(name="分页查询列表",path = "/queryListPage",requiredPermission = false)
    @ApiOperation(value="分页查询列表",response = MaterialResult.class)
    public ResponseData queryListPage(MaterialParam materialParam){

        return ResponseData.success(materialService.queryListPage(materialParam));
    }

    @PostResource(name = "增添",path = "addFirst",requiredPermission = false,requiredLogin = false)
    @ApiOperation(value = "增添")
    public ResponseData addFirst(@RequestBody MaterialParam materialParam){
        materialService.addFirst(materialParam);
        return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"添加成功","null");
    }

    @PostResource(name="修改",path = "/update",requiredLogin = false,requiredPermission = false)
    @ApiOperation(value = "修改")
    public ResponseData updateOne(@RequestBody MaterialParam materialParam){
        materialService.updateOne(materialParam);
        return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"修改成功","null");
    }

    @PostResource(name = "删除",path = "/delete",requiredLogin = false,requiredPermission = false)
    @ApiOperation(value="删除")
    public ResponseData deleteOne(@RequestParam Long fid){
       materialService.deleteOne(fid);
       return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"删除成功","null");
    }

}
